/****************************************************************************
    
    analogDelay_gtk.cpp - GUI for the analogDelay plugin
    
    Copyright (C) 2007  Robert Gruendler <r.gruendler@gmail.com>
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.
    
    You should have received a copy of the GNU Lesser General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 01222-1307  USA

****************************************************************************/

#include <iostream>
#include <vector>
#include <gtkmm.h>
#include "lv2gtk2gui.hpp"
#include "analogdelay.peg"
#include "SimpleDial.h"



using namespace sigc;
using namespace Gtk;
using namespace std;


class AnalogDelayGUI : public LV2GTK2GUI {
public:

	AnalogDelayGUI(LV2Controller& ctrl, const std::string& URI, 
			const std::string& bundle_path) 
	: m_gain(0.0, 1.0, 0.001),
	m_ctrl(ctrl)

	{

		pack_start(m_vbox);

		// initialise control widget
		m_gain.set_digits(2);
		m_gain.set_draw_value(true);
		m_gain.set_value_pos(POS_RIGHT);
		m_gain.set_value(0);
		
		
				
		
		
		// layout
		Table* table = manage(new Table(3, 3));
		table->set_border_width(6);
		table->set_spacings(6);
		table->attach(m_gain, 2, 3, 2, 3);
		table->attach(dial, 2, 3, 1, 2);
	
		
		
		m_vbox.pack_start(*table);

		// connect signal

		this->set_size_request(400,300);


		m_gain.signal_value_changed().
		connect(bind(mem_fun(*this, &AnalogDelayGUI::handle_gain_change), ref(ctrl)));

	}

protected:


	void handle_gain_change(LV2Controller& ctrl) {

		float value = m_gain.get_value();
		ctrl.write(k_control1, 1, &value);

	}


	LV2Controller& m_ctrl;
	HScale m_gain;
	VBox m_vbox;
	VBox k_vbox;
	SimpleDial dial;
	
	
	

};


void initialise() __attribute__((constructor));
void initialise() {
	register_lv2gtk2gui<AnalogDelayGUI>(std::string(k_uri) + "/gui");
}
